package group;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;

public class GroupTask {
	
	ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
	/**
	 * 部署流程定义
	 */
	@Test
	public void deploymentProcessDdfinition(){
		
		RepositoryService service = processEngine.getRepositoryService();  //于流程定义和相关的servers
		 
		DeploymentBuilder builder = service.createDeployment(); 	//创建一个部署对象
		builder.name("组任务");
		builder.addClasspathResource("group/group.bpmn");
		builder.addClasspathResource("group/group.png");
	
		Deployment deployment = builder.deploy();	//完成部署
		
		System.out.println(deployment.getId());
		System.out.println(deployment.getName());
	}
	
	@Test
	public void startProcessInstance(){
		String processDefinitionKey = "task";
//		Map<String, Object> variables = new HashMap<>();
//		variables.put("userID", "周芷若");
		
		ProcessInstance pi= processEngine.getRuntimeService()	//于正在执行的流程实力和执行的兑现相关的Service
					.startProcessInstanceByKey(processDefinitionKey);  //使用流程定义的key启动流程实例
		System.out.println("|----------------------------");
		System.out.println(pi.getId());
		System.out.println(pi.getProcessDefinitionId());
	}
	
	@Test
	public void findMypersonTask(){
		
		String assignee = "张三丰";
		List<Task> list  = processEngine.getTaskService().createTaskQuery().taskAssignee(assignee).list();
		if (list != null && list.size() > 0 ) {
			for (Task task : list) {
				System.out.println("任务id："+ task.getId());
				System.out.println("任务名称："+task.getName());
				System.out.println("任务创建时间："+task.getCreateTime());
				System.out.println("任务办理人："+task.getAssignee());
			}
		}
	}
	
	
	@Test
	public void completeMyPersonalTask(){
		String taskId = "2504";
		Map<String, Object> varible = new HashMap<String, Object>();
		varible.put("message", "不重要");
		processEngine.getTaskService() .complete(taskId, varible);
		System.out.println("完成任务：任务ID"+taskId);
	}
}
